package com.bw.widget_sdk.widget;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.bw.widget_sdk.R;
import com.scwang.smart.refresh.layout.api.RefreshHeader;
import com.scwang.smart.refresh.layout.api.RefreshKernel;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.constant.RefreshState;
import com.scwang.smart.refresh.layout.constant.SpinnerStyle;
import com.yanyusong.y_divideritemdecoration.Dp2Px;

//https://github.com/scwang90/SmartRefreshLayout/blob/master/art/md_custom.md
public class ShopHeader extends LinearLayout implements RefreshHeader {

    private View rootView;
    private TextView shop_head_tv;

    public ShopHeader(Context context) {
        super(context);
        rootView = LayoutInflater.from(context).inflate(R.layout.layout_shop_head,null,false);
        shop_head_tv = rootView.findViewById(R.id.shop_head_tv);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
                LayoutParams.MATCH_PARENT, Dp2Px.convert(context,90));
        rootView.setLayoutParams(layoutParams);
        addView(rootView);
    }

    @NonNull
    @Override
    public View getView() {
        return this;
    }

    @NonNull
    @Override
    public SpinnerStyle getSpinnerStyle() {
        return SpinnerStyle.Translate;
    }

    @Override
    public void setPrimaryColors(int... colors) {

    }

    @Override
    public void onInitialized(@NonNull RefreshKernel kernel, int height, int maxDragHeight) {

    }

    @Override
    public void onMoving(boolean isDragging, float percent, int offset, int height, int maxDragHeight) {

    }

    @Override
    public void onReleased(@NonNull RefreshLayout refreshLayout, int height, int maxDragHeight) {

    }

    @Override
    public void onStartAnimator(@NonNull RefreshLayout refreshLayout, int height, int maxDragHeight) {

    }

    @Override
    public int onFinish(@NonNull RefreshLayout refreshLayout, boolean success) {
        return 0;
    }

    @Override
    public void onHorizontalDrag(float percentX, int offsetX, int offsetMax) {

    }

    @Override
    public boolean isSupportHorizontalDrag() {
        return false;
    }

    @Override
    public void onStateChanged(@NonNull RefreshLayout refreshLayout,
                               @NonNull RefreshState oldState,
                               @NonNull RefreshState newState) {
        switch (newState){
            case None:
            case PullDownToRefresh:
                shop_head_tv.setText("下拉刷新");
                break;
            case Refreshing:
                shop_head_tv.setText("正在刷新");
                break;
            case ReleaseToRefresh:
                shop_head_tv.setText("释放刷新");
                break;
        }
    }
}
